package com.feeyo.prophet.config;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 单例模式class,反射单例数据
 */
public class ParametersSingletonManager {
    private static final ConcurrentHashMap<String, String> cache = new ConcurrentHashMap<>();

    private ParametersSingletonManager() {
    }
    public static String getParameters(String key, ParametersSupplier supplier) {
        synchronized (cache) {
            if (!cache.containsKey(key)) {
                cache.put(key, supplier.get());
            }
            return cache.get(key);
        }
    }
    @FunctionalInterface
    public interface ParametersSupplier {
        String get();
    }
}
